<template>
  <div class="login-container">
    <el-form ref="form" :model="from" label-width="80px" class="login-form">
      <h2 class="login-title">管理系统</h2>
      <!-- 用户名 <input type="text" v-model="user.loginName"/><br/>
       密码<input type="text" v-model="user.password"/><br/>
       <input type="button" @click="index" value="登录"/>-->
      <el-form-item label="用户名">
        <el-input v-model="user.loginName"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input type="password" v-model="user.password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="index">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  import axios from 'axios';

  export default {
    data() {
      return {
        user: {}
      }
    },

    methods: {
      index: function () {
        axios.post("/api/login", this.user).then(res => {
          if (res.data = "success") {
            alert("登录成功")
            this.$router.push("/back")
          } else {
            alert("登录失败")
          }
        })
      },

    }
  }
</script>

<style scoped>
  .login-form {
    width: 350px;
    margin: 160px auto; /* 上下间距160px，左右自动居中*/
    background-color: rgb(255, 255, 255); /* 透明背景色 */
    padding: 30px;
    border-radius: 20px; /* 圆角 */
  }

  /* 背景 */
  .login-container {

    position: absolute;
    width: 100%;
    height: 100%;
    background: url("../assets/css.jpg");
    background-size: 100% 100%;
    background-repeat:no-repeat;
  }

  /* 标题 */
  .login-title {
    color: #303133;
    text-align: center;
  }
</style>

